from app import db
from datetime import datetime

class GepParameter(db.Model):
    """GEP核算参数模型"""
    __tablename__ = 'gep_parameters'
    
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False, comment='核算年份')
    gepCity = db.Column(db.String(50), nullable=False, comment='市级地区名称')
    gepDistrict = db.Column(db.String(50), nullable=False, comment='区级地区名称')
    gepTown = db.Column(db.String(50), nullable=False, comment='镇级地区名称')
    inAgricultural = db.Column(db.Float, comment='农业产值（万元）')
    inForestry = db.Column(db.Float, comment='林业产值（万元）')
    inAnimalHusbandry = db.Column(db.Float, comment='牧业产值（万元）')
    inFishery = db.Column(db.Float, comment='渔业产值（万元）')
    inEcologicalEnergy = db.Column(db.Float, comment='生态能源发电量（万千瓦时）')
    inElectricityPrice = db.Column(db.Float, comment='电价（元/千瓦时）')
    inWaterResources = db.Column(db.Float, comment='水资源总量（万立方米）')
    inLocalWaterPrice = db.Column(db.Float, comment='当地水价（元/立方米）')
    inProtectedArea = db.Column(db.Float, comment='保护区面积（平方千米）')
    inProtectedCost = db.Column(db.Float, comment='保育成本（万元/平方千米）')
    inNoiseReductionAmount = db.Column(db.Float, comment='噪声消减量（万dB）')
    inNoiseCost = db.Column(db.Float, comment='噪声降低成本（元/dB）')
    inTourismRevenue = db.Column(db.Float, comment='旅游收入（万元）')
    inHousingAreaPerCapita = db.Column(db.Float, comment='城镇人均住房面积（平方米）')
    inHousePrice = db.Column(db.Float, comment='当地房价（元/平方米）')
    inHotelRooms = db.Column(db.Float, comment='酒店客房总数（间）')
    inRoomPrice = db.Column(db.Float, comment='客房价格（元/间）')
    inUrbanPopulation = db.Column(db.Float, comment='城镇常住人口（万人）')
    inOccupancyRate = db.Column(db.Float, comment='年入住率（%）')
    inLeisureTime = db.Column(db.Float, comment='日休闲游憩时间（时/天人）')
    inAverageIncome = db.Column(db.Float, comment='人均工资（元/人时）')
    creator = db.Column(db.String(50), comment='数据创建者用户名')
    updater = db.Column(db.String(50), comment='数据更新者用户名')
    created_at = db.Column(db.DateTime, default=datetime.utcnow, comment='数据创建时间')
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment='数据更新时间')
    
    def __repr__(self):
        return f'<GepParameter {self.year}-{self.gepCity}-{self.gepDistrict}-{self.gepTown}>'
    
    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'gepCity': self.gepCity,
            'gepDistrict': self.gepDistrict,
            'gepTown': self.gepTown,
            'inAgricultural': self.inAgricultural,
            'inForestry': self.inForestry,
            'inAnimalHusbandry': self.inAnimalHusbandry,
            'inFishery': self.inFishery,
            'inEcologicalEnergy': self.inEcologicalEnergy,
            'inElectricityPrice': self.inElectricityPrice,
            'inWaterResources': self.inWaterResources,
            'inLocalWaterPrice': self.inLocalWaterPrice,
            'inProtectedArea': self.inProtectedArea,
            'inProtectedCost': self.inProtectedCost,
            'inNoiseReductionAmount': self.inNoiseReductionAmount,
            'inNoiseCost': self.inNoiseCost,
            'inTourismRevenue': self.inTourismRevenue,
            'inHousingAreaPerCapita': self.inHousingAreaPerCapita,
            'inHousePrice': self.inHousePrice,
            'inHotelRooms': self.inHotelRooms,
            'inRoomPrice': self.inRoomPrice,
            'inUrbanPopulation': self.inUrbanPopulation,
            'inOccupancyRate': self.inOccupancyRate,
            'inLeisureTime': self.inLeisureTime,
            'inAverageIncome': self.inAverageIncome,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        } 